const UserRightsModel = require('../model').userRightsModel;
let DaoTool = require('../lib/daoTool');

exports.createRights = function (conn, params) {
    return new Promise(function (resolve, reject) {
        let sql = "insert into user_rights set ?";
        conn.query(sql, [DaoTool.generateModelObject(params, UserRightsModel, 'create')], function (err, result) {
            printLog("=createRights=", this.sql);
            if (err) reject(err);
            resolve(result)
        });
    });
};
exports.queryRights = function (conn, params) {
    return new Promise(function (resolve, reject) {
        let sql = "select * from user_rights where openid = ? ;";
        conn.query(sql, [params.openid], function (err, result) {
            printLog("=queryRights=", this.sql);
            if (err) reject(err);
            resolve(result)
        });
    });
};
//更新
exports.updateRights = function (conn, params) {
    return new Promise(function (resolve, reject) {
        conn.query('update user_rights set ? where openid=?;', [DaoTool.generateModelObject(params, UserRightsModel, 'update'), params.openid], function (err, result) {
            printLog("=updateRights =", this.sql);
            if (err) reject(err);
            resolve(result);
        });
    });
};